// pages/activity/special/special.js
let common = require('../../../utils/common.js');
Page({
  data: {},
  id: 0,
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.id = options.id;
    this.registerEvent();
  },
  registerEvent: function () {
    this.reqDetail();
  },
  reqDetail: function () {
    let that = this;
    common.asynPost(common.API.activity.detail, {
      id: that.id
    }, function (data) {
      if (data['detail']) {
        that.setData({
          detail: data['detail']
        });
      }
    }, function (data) {
      console.log(data)
    });
  },
  specialBook: function () {
    let isApply = this.data.detail.isApply;
    if (typeof isApply == 'undefined' || isApply == 1) {
      wx.showToast({ title: '专场报名未开始' });
    } else if (isApply == 2) {
      wx.showToast({ title: '专场报名已结束' });
    } else {
      var json = {
        id: this.data.detail.id,
        title: this.data.detail.title,
        subhead: this.data.detail.subhead,
        startTime: this.data.detail.startTime,
        address: this.data.detail.address,
        price: this.data.detail.price,
        cover: this.data.detail.cover
      }
      wx.navigateTo({
        url: '../book/book?detail=' + JSON.stringify(json)
      });
    }
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  onShareAppMessage() {
    return {
      title: this.data.detail['title'],
      desc: this.data.detail['subhead'],
      path: 'pages/activity/special/special?id=' + this.data.detail.id
    }
  }
})